<template>
  <div id="app">
    <TopBar :key="TopBarKey" />
    <Header />
    <router-view></router-view>
    <Footer />
    <Login v-show="isShowLoginModal" />
    <transition name="slide"><Toast v-show="isShowToast" /></transition>
  </div>
</template>

<script>
import TopBar from "./components/TopBar.vue";
import Header from "./components/Header.vue";
import Footer from "./components/Footer.vue";
import Login from "./components/Login.vue";
import Toast from "./components/Toast.vue";

import { recommendAPI } from "./request/api";
import { mapState } from "vuex";
export default {
  components: {
    TopBar,
    Header,
    Footer,
    Login,
    Toast,
  },
  computed: {
    ...mapState({
      isShowLoginModal: (state) => state.showModal.isShowLoginModal,
      isShowToast: (state) => state.showToast.isShowToast,
    }),
  },
  data() {
    return {
      TopBarKey: 0,
    };
  },

  watch: {
    // 监听路由的变化
    "$route.path"() {
      // key属性的值一变化，就会TopBar组件重载，从而执行created函数
      this.TopBarKey++;
    },
  },
};
</script>

<style lang="less">
#app {
}
.slide-enter,
.slide-leave-to {
  opacity: 0;
}

.slide-enter-active,
.slide-leave-active {
  transition: opacity 0.3s linear;
}

.slide-enter-to,
.slide-leave {
  opacity: 0;
}
</style>
